<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019/8/14
  Time: 9:46
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="f" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>Title</title>
    <script type="text/javascript" src="<c:url value='/js/jquery-1.8.2.js'/>"></script>
</head>
<body>
    <center>
        <h1>正在给${gb.gname}班级分配讲师<br>

        </h1>
        <form action="<c:url value='/updateGradeTeacher.do'/>" method="post">
            <input type="hidden" name="gid" value="${gb.gid}"/>
            讲师：<select name="tid" onchange="changeteacher(this)">
                    <option value="-1">--请选择--</option>
                    <c:forEach var="t" items="${list}">
                        <option value="${t.tid}" ${t.tid==gb.tb.tid?'selected':''}>${t.tname}
                        </option>
                    </c:forEach>
                 </select>
            <input type="submit"  id="bcan" value="提交"/>
        </form>
    </center>
<script>
    function changeteacher(obj) {
        $.post(
            "<c:url value='/getTeacherByTid.do'/>",
            {tid:obj.value},
            function (data) {
                $("#bcan").attr("disabled",false);
                if(data == '1'){
                    confirm("该讲师已经有一个班级了，每个讲师最多只能带两个班级")
                }else if(data=='2'){
                    confirm("该讲师已经有两个班级了，不能在带班了")
                    $("#bcan").attr("disabled",true);
                }
            }
        )
    }
</script>
</body>
</html>
